#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "esp_log.h"
#include "ota.h"
#include "http_request.h"
#include "http_server.h"

static const char *TAG = "OTA/Http";

uint8_t ota_http_update_url(uint8_t type, char *url)
{
    if (!ota_default_handle)
        return 0;
    if (type == 0xFF)
        return 0;
    uint8_t re = 0;
    http_server->ws.process = 1;
    if (type & OTA_TYPE_APP)
    {
        ESP_LOGI(TAG, "Start ota app partition.");
        re = http_request_from_url("GET", url, NULL, 0, ota_app_bin_stream_process_cb, ota_default_handle, http_stream_header_cb);
    }
    else if (type & OTA_TYPE_WWW)
    {
        ESP_LOGI(TAG, "Start ota www partition.");
        re = http_request_from_url("GET", url, NULL, 0, ota_www_bin_stream_process_cb, ota_default_handle, http_stream_header_cb);
    }
    http_server->ws.process = 0;
    return re;
}